import streamlit as st

# ——文本与标题————————————————————————————————————————————————————————————————————————————————
st.title("主标题")
st.header("副标题")
st.subheader("小标题")
st.text("普通文本")
st.write("Hello, *World!* :sunglasses:")
st.markdown("*Streamlit* is **really** ***cool***.")
st.markdown('''
:red[Streamlit] :orange[can] :green[write] :blue[text] :violet[in]
:gray[pretty] :rainbow[colors] and :blue-background[highlight] text.''')
st.markdown("Here's a bouquet &mdash;\
:tulip::cherry_blossom::rose::hibiscus::sunflower::blossom:")
st.markdown("""
### 学生成绩分析报告
- **优秀率**: 15%
- **及格率**: 95%
- [查看详情](http://www.baidu.com)
""")

# ——表格————————————————————————————————————————————————————————————————————————
import pandas as pd
# 生成DataFrame数据
df = pd.DataFrame({
    "学号":range(1,6),
    "姓名":["张三", "李四", "王五", "赵六", "常旭"],
    "成绩":[90,91,89,100,78]
})
# 显示静态表格（适合打印）
st.table(df)
# 显示交互式表格
st.dataframe(df)
st.dataframe(df.style.highlight_max(color="lightyellow"))

# ———代码———————————————————————————————————————————————————————————————————————————
code_str = """
print("hello world!")

def main():
    print("我是一个函数")
"""
st.code(code_str, language="python", line_numbers=True)

# ——可视化图表—————————————————————————————————————————————————————————————————————————————————
import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.plot([1, 2, 3], [4, 5, 1])
ax2.bar([1, 2, 3], [4, 5, 1])
st.pyplot(fig, use_container_width=False)

import altair as alt
chart = alt.Chart(df).mark_bar().encode(
    x="姓名",
    y="成绩"
)
st.altair_chart(chart)

import plotly.express as px
px_fig = px.bar(df, x="姓名", y="成绩")
st.plotly_chart(px_fig)





